home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZIWINDOW.CPP < prev    next >
C/C++ Source or Header  |  1995-09-20  |  34KB  |  1,170 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zn.cpp
  5. //   Title:    Zinc Window Template
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_WINDOW.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_MAIN
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50. //----------------------------------------------------------------------------
  51. //
  52. //----------------------------------------------------------------------------
  53. PZI_CANCEL ZI_WINDOW::pzi_cancel = NULL;
  54. BOOL ZI_WINDOW::fAbort = FALSE;
  55.  
  56.  
  57. //----------------------------------------------------------------------------
  58. //   Description:    Default constructor
  59. //    Parameters:
  60. //       Returns:    
  61. //----------------------------------------------------------------------------
  62. FN_M ZI_WINDOW::ZI_WINDOW() :
  63.     ZN_WINDOW(ZiMainWindow(), ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  64. {
  65.     ZI_WINDOW::Initialize(CL_INIT_CLASS);
  66.     Setup();
  67. }
  68.  
  69.  
  70. //----------------------------------------------------------------------------
  71. //   Description:    Destructor
  72. //    Parameters:
  73. //       Returns:    
  74. //----------------------------------------------------------------------------
  75. FN_M ZI_WINDOW::~ZI_WINDOW()
  76. {
  77.     ZI_WINDOW::Destroy(FALSE);
  78.     Terminate();
  79. }
  80.  
  81.  
  82. //----------------------------------------------------------------------------
  83. //   Description:    
  84. //    Parameters:
  85. //       Returns:    TRUE if successful.
  86. //----------------------------------------------------------------------------
  87. BOOL FN_M ZI_WINDOW::Abbrev()
  88. {
  89.     if (!CheckCounter())
  90.         return FALSE;
  91.  
  92.     PZI_ABBREV pzi_abbrev = new ZI_ABBREV;
  93.     if (pzi_abbrev == NULL)
  94.        return ErrorNoMem();
  95.     else if (pzi_abbrev->IsValid())
  96.        pzi_abbrev->Show();
  97.  
  98.     return TRUE;
  99. }
  100.  
  101.  
  102. //----------------------------------------------------------------------------
  103. //   Description:    
  104. //    Parameters:
  105. //       Returns:    TRUE if successful.
  106. //----------------------------------------------------------------------------
  107. BOOL FN_M ZI_WINDOW::CheckCounter()
  108. {
  109.     if (lRecordCount <= 0)
  110.         {
  111.        PZI_COUNTER pzi_counter = new ZI_COUNTER;
  112.        if (pzi_counter == NULL)
  113.             return ErrorNoMem();
  114.         else if (pzi_counter->IsValid())
  115.            pzi_counter->Show();
  116.  
  117.         return FALSE;
  118.         }
  119.     return TRUE;
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------------
  124. //   Description:    
  125. //    Parameters:
  126. //       Returns:    TRUE if successful.
  127. //----------------------------------------------------------------------------
  128. VOID FN_M ZI_WINDOW::Clear(BOOL fInput, BOOL fOutput)
  129. {
  130.     if (fOutput)
  131.         {
  132.        SetString(FID(STR_RESULT1));
  133.        SetString(FID(STR_RESULT2));
  134.        SetString(FID(STR_RESULT3));
  135.        SetString(FID(STR_RESULT4), "Enter address and select Search.");
  136.        SetString(FID(STR_OUTPUT_ADDR2));
  137.        SetString(FID(STR_OUTPUT_LL));
  138.        strcpy(szResults,
  139.             "Enter an address, then select the 'Search' button. "
  140.             "A city and state, 5 digit ZIP code, 9 digit ZIP code, or "
  141.             "full address may be entered.\r\n");
  142.         LoadIconBitmap(FID(ICON_MAILBOX), "MAILBOX");
  143.         z4_inq.std.szAddress[0] = '\0';
  144.         }
  145.     if (fInput)
  146.         {
  147. //       SetString(FID(STR_INPUT_ADDR1));
  148.        SetString(FID(STR_INPUT_ADDR2));
  149.        SetString(FID(STR_INPUT_CITY));
  150.        SetString(FID(STR_INPUT_ST));
  151.        SetString(FID(STR_INPUT_ZIP));
  152.         }
  153.     SetCurrent(FID(STR_INPUT_ADDR2));
  154.     return ;
  155. }
  156.  
  157.  
  158. //----------------------------------------------------------------------------
  159. //   Description:    
  160. //    Parameters:
  161. //       Returns:    TRUE if successful.
  162. //----------------------------------------------------------------------------
  163. BOOL FN_M ZI_WINDOW::Configure()
  164. {
  165.     PZI_CONFIG pzi_config = new ZI_CONFIG;
  166.     if (pzi_config == NULL)
  167.        return ErrorNoMem();
  168.     else if (pzi_config->IsValid())
  169.        pzi_config->Show();
  170.     return TRUE;
  171. }
  172.  
  173.  
  174. //----------------------------------------------------------------------------
  175. //   Description:    Display city/state list
  176. //    Parameters:
  177. //       Returns:    TRUE if successful.
  178. //----------------------------------------------------------------------------
  179. BOOL FN_M ZI_WINDOW::CS()
  180. {
  181.     if (!CheckCounter())
  182.         return FALSE;
  183.  
  184.     Get();
  185.     z4_inq.parse.LastLine(z4_inq.szZip, z4_inq.szCity, z4_inq.szState);
  186.  
  187.     PZI_CS pzi_cs = new ZI_CS(z4_inq.parse.state, z4_inq.parse.szCity);
  188.     if (pzi_cs == NULL)
  189.         return ErrorNoMem();
  190.     else if (pzi_cs->IsValid())
  191.         pzi_cs->Show();
  192.     return TRUE;
  193. }
  194.  
  195.  
  196. //----------------------------------------------------------------------------
  197. //   Description:    Display city/state list
  198. //    Parameters:
  199. //       Returns:    TRUE if successful.
  200. //----------------------------------------------------------------------------
  201. BOOL FN_M ZI_WINDOW::CX()
  202. {
  203.     if (!CheckCounter())
  204.         return FALSE;
  205.  
  206.     Get();
  207.     z4_inq.parse.LastLine(z4_inq.szZip, z4_inq.szCity, z4_inq.szState);
  208.  
  209.     PZI_CX pzi_cx = new ZI_CX(z4_inq.parse.state, z4_inq.parse.szCity);
  210.     if (pzi_cx == NULL)
  211.        return ErrorNoMem();
  212.     else if (pzi_cx->IsValid())
  213.        pzi_cx->Show();
  214.     return TRUE;
  215. }
  216.  
  217.  
  218. //----------------------------------------------------------------------------
  219. //   Description:    Destroy object. Free any resources used by object.
  220. //                          Normally called by destructor.
  221. //                        Should allow multiple calls from various classes.
  222. //                        A class should almost always re-init its variables when 
  223. //                        it is destroyed to prevent accidents.
  224. //    Parameters:    fDestroyAll        Destroy parents also?
  225. //                                            Default is TRUE.
  226. //       Returns:    TRUE if successful.
  227. //----------------------------------------------------------------------------
  228. BOOL FN_M ZI_WINDOW::Destroy(BOOL fDestroyAll)
  229. {
  230.     z4_inq.Destroy();                            // Close inquiry class
  231.     ZI_WINDOW::Initialize(CL_INIT_CLASS_VARS);
  232.     if (fDestroyAll)                            // Destroy parent.
  233.         ZI_WINDOW_PARENT::Destroy(fDestroyAll);
  234.     return TRUE;
  235. }
  236.  
  237.  
  238. //----------------------------------------------------------------------------
  239. //   Description:    
  240. //    Parameters:
  241. //       Returns:    TRUE if successful.
  242. //----------------------------------------------------------------------------
  243. BOOL FN_M ZI_WINDOW::Expert()
  244. {
  245.     PZI_EXPERT pzi_expert = new ZI_EXPERT;
  246.     if (pzi_expert == NULL)
  247.        return ErrorNoMem();
  248.     else if (pzi_expert->IsValid())
  249.        pzi_expert->Show();
  250.     return TRUE;
  251. }
  252.  
  253. //----------------------------------------------------------------------------
  254. //   Description:    
  255. //    Parameters:
  256. //       Returns:    TRUE if successful.
  257. //----------------------------------------------------------------------------
  258. VOID FN_M ZI_WINDOW::Flags()
  259. {
  260.     if (z4_inq.fZip5Changed)
  261.         {
  262.         strcat(szResults, "The 5 digit ZIP code was added or corrected.\r\n");
  263.         }
  264.     if (z4_inq.fCSChanged)
  265.         {
  266.         strcat(szResults, "The city/state was added or corrected.\r\n");
  267.         }
  268.     if (z4_inq.fAddrChanged)
  269.         {
  270.         strcat(szResults, "The address line was corrected (standardized).\r\n");
  271.         }
  272.     if (z4_inq.fBetterAvailable)
  273.         {
  274.         strcat(szResults,
  275.             "A better record may be available by entering a BOX number "
  276.             "or by entering the building or business name.\r\n");
  277.         }
  278.     if (z4_inq.fNonDeliverable)
  279.         {
  280.         strcat(szResults,
  281.             "The address was verified, but the United States Postal Service "
  282.             "does not deliver mail to the specified address.\r\n");
  283.         }
  284.     if (z4_inq.fFacilityOther)
  285.         {
  286.         strcat(szResults,
  287.             "The city name was not acceptable for use on mail, "
  288.             "the city name of the main post office was substituted.\r\n");
  289.         }
  290.     if (z4_inq.fNoPrimary)
  291.         {
  292.         strcat(szResults,
  293.             "No street or box number was entered, or it is invalid. "
  294.             "All records with the input street name were selected.\r\n");
  295.         }
  296.     if (z4_inq.fSecAvail)
  297.         {
  298.         strcat(szResults,
  299.             "Secondary delivery points are available at this address (APT/BOX/etc..). "
  300.             "A better ZIP+4 may be obtained by entering a valid secondary number.\r\n");
  301.         }
  302.     if (z4_inq.fInvSec)
  303.         {
  304.         strcat(szResults,
  305.             "The input secondary number (APT/BOX/etc...) was invalid.)\r\n");
  306.         }
  307.     if (z4_inq.fInvZip4)
  308.         {
  309.         strcat(szResults, "An invalid ZIP+4 code was entered.\r\n");
  310.         }
  311.     if (z4_inq.fInvCity)
  312.         {
  313.         strcat(szResults, "An unrecognized or blank city name was entered.\r\n");
  314.         }
  315.     if (z4_inq.fInvState)
  316.         {
  317.         strcat(szResults, "An invalid state code was entered.\r\n");
  318.         }
  319.     if (z4_inq.fInvZip5)
  320.         {
  321.         strcat(szResults, "An invalid 5 digit ZIP code was entered.\r\n");
  322.         }
  323.     if (z4_inq.fStackOverFlow)
  324.         {
  325.         strcat(szResults,
  326.             "A large number of potential matching records were found. "
  327.             "Not all matches are available for viewing.\r\n");
  328.         }
  329.     Assert(strlen(szResults) < sizeof(szResults));
  330.     return ;
  331. }
  332.  
  333. //----------------------------------------------------------------------------
  334. //   Description:    
  335. //    Parameters:    
  336. //       Returns:    
  337. //----------------------------------------------------------------------------
  338. BOOL FN_M ZI_WINDOW::Get()
  339. {
  340.     PCSZ pcszCity  = strskipws(GetString(FID(STR_INPUT_CITY)));
  341.     PCSZ pcszState = strskipws(GetString(FID(STR_INPUT_ST)));
  342.     PCSZ pcszZip   = strskipws(GetString(FID(STR_INPUT_ZIP)));
  343.     PCSZ pcszAddr1 = NULL;
  344.     PCSZ pcszAddr2 = strskipws(GetString(FID(STR_INPUT_ADDR2)));
  345.  
  346.     z4_inq.Set(pcszCity, pcszState, pcszZip, pcszAddr1, pcszAddr2);
  347.     return pcszCity[0] || pcszState[0] || pcszZip[0] || pcszAddr2[0];
  348. }
  349.  
  350.  
  351. //----------------------------------------------------------------------------
  352. //   Description:    Display help bar text for the current help context.
  353. //    Parameters:    
  354. //       Returns:    
  355. //----------------------------------------------------------------------------
  356. VOID FN_M ZI_WINDOW::Help(ZN_HELP help, PSZ psz)
  357. {
  358. static ZN_HELPMAP aHelpMap[] =
  359.     {
  360.     { HELP_ADDR_INPUT   , "Enter an address." },
  361.     { HELP_CITY_INPUT   , "Enter a city name." },
  362.     { HELP_ST_INPUT     , "Enter a valid state code." },
  363.     { HELP_ZIP_INPUT    , "Enter a 5 or 9 digit ZIP code." },
  364.     { HELP_MAIN_SEARCH  , "Search for an address." },
  365.     { HELP_MAIN_MESSAGES, "View additional search information." },
  366.     { HELP_MAIN_COPY    , "Copy standardized address to clipboard." },
  367.     { HELP_MAIN_CLEAR   , "Clear input and output fields." },
  368.     { HELP_TOOL_CITY    , "View city name list." },
  369.     { HELP_TOOL_ST      , "View state list." },
  370.     { HELP_TOOL_HELP    , "View help index." },
  371.     { HELP_TOOL_PRODUCTS, "View additional product information." },
  372.     { 0, NULL }
  373.     };
  374.     ZN_WINDOW::Help(aHelpMap, help, psz);
  375.     return;
  376. }
  377.  
  378.  
  379. //----------------------------------------------------------------------------
  380. //   Description:    
  381. //    Parameters:
  382. //       Returns:    TRUE if successful.
  383. //----------------------------------------------------------------------------
  384. BOOL FN_M ZI_WINDOW::HelpIndex()
  385. {
  386.     PZI_HELP pzi_help = new ZI_HELP;
  387.     if (pzi_help == NULL)
  388.         return ErrorNoMem();
  389.     else if (pzi_help->IsValid())
  390.         pzi_help->Show();
  391.     return TRUE;
  392. }
  393.  
  394.  
  395. //----------------------------------------------------------------------------
  396. //   Description:    Initialize object. 
  397. //                          Normally called by constructor.
  398. //                        Should allow multiple calls from various classes.
  399. //    Parameters:    sInit        Initialization code. May be one of the following:
  400. // CL_INIT_CLASS                   Reset class variables and
  401. //                                                         and dynamic allocations for
  402. //                                                         this class only.
  403. // CL_INIT_CLASS_VARS      Reset class variables for
  404. //                                                         this class only.
  405. // CL_INIT_VARS                    Reset class variables for
  406. //                                                         this class only.
  407. // CL_INIT_ALL                             Initialize class and all
  408. //                                                         parent class, including
  409. //                                                         dynamic memory allocation.
  410. //                                    Default is CL_INIT_ALL
  411. //       Returns:    TRUE if successful.
  412. //----------------------------------------------------------------------------
  413. BOOL FN_M ZI_WINDOW::Initialize(SHORT sInit)
  414. {
  415.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  416.         ZI_WINDOW_PARENT::Initialize(sInit);
  417.  
  418.     lRecordCount = 0;
  419.     z4_inq.pfnzip4 = Z4Callback;
  420.     return TRUE;
  421. }
  422.  
  423.  
  424. //----------------------------------------------------------------------------
  425. //   Description:
  426. //    Parameters:    
  427. //       Returns:    
  428. //----------------------------------------------------------------------------
  429. VOID FN_M ZI_WINDOW::Inquiry()
  430. {
  431.     if (!CheckCounter())
  432.         return ;
  433.     Clear(FALSE,TRUE);
  434.     if (!Get())                                    // Make sure something has been input
  435.         return ;
  436.  
  437.     SetString(FID(STR_RESULT3));
  438.     SetString(FID(STR_RESULT4), "Searching...");
  439.     SetMouse(MOUSE_HOURGLASS);
  440.     fAbort = FALSE;
  441.     pzi_cancel = new ZI_CANCEL;
  442.     BOOL fInquiry = z4_inq.Inquiry();
  443.     if (pzi_cancel)
  444.         {
  445.         pzi_cancel->Close();
  446.         Process();
  447.         }
  448.     SetCurrent(FID(STR_INPUT_ADDR2));
  449.     SetMouse();
  450.     if (!fInquiry                                // Perform the inquiry
  451.         || (z4_inq.result != Z4_RESULT_EXACT
  452.     && z4_inq.result != Z4_RESULT_MULTI))
  453.         {
  454.         SetResults();
  455.         return ;
  456.         }
  457.     LoadIconBitmap(FID(ICON_MAILBOX), "MAILBOX2");
  458.     if (z4_inq.match.cRecords > 1 && z4_inq.result == Z4_RESULT_MULTI)
  459.         {
  460.         SetString(FID(STR_RESULT4), "Multiple responses.");
  461.        SHORT sResult = ZincMessageBox("Multiple Records Matched",
  462.            ZN_MBOX_OKCANCEL,
  463.             "Multiple records were found which were similar to the input. "
  464.             "Select the OK button to view the records. The INQUIRY count "
  465.             "will decrease by one. "
  466.             "Select Cancel to return to the main screen.");
  467.    
  468.        strcpy(szResults,
  469.            "Multiple records were found which were similar to the input. "
  470.            "The inquiry was cancelled.");
  471.  
  472.         //
  473.         //    This is the default message in case the user aborts
  474.         //
  475.        if (sResult != ZN_MID_OK)
  476.            {
  477.            SetString(FID(STR_RESULT3), "Inquiry cancelled by user.");
  478.             SetString(FID(STR_RESULT4));
  479.             return ;
  480.            }
  481.        strcpy(szResults,
  482.            "Multiple records were found which were similar to the input. "
  483.            "None of the choices were selected.");
  484.  
  485.         Multiple();
  486.         }
  487.     else
  488.         SetResults();
  489.  
  490.     User(ZI_MSG_CLICK);                        // Remove one click from the meter
  491.     SetCurrent(FID(STR_INPUT_ADDR2));
  492.     return ;
  493. }
  494.  
  495.  
  496. //----------------------------------------------------------------------------
  497. //   Description:    
  498. //    Parameters:
  499. //       Returns:    TRUE if successful.
  500. //----------------------------------------------------------------------------
  501. BOOL FN_M ZI_WINDOW::More()
  502. {
  503.     PZI_MORE pzi_more = new ZI_MORE;
  504.     if (pzi_more == NULL)
  505.        return ErrorNoMem();
  506.     else if (pzi_more->IsValid())
  507.        {
  508.        pzi_more->Show();
  509.         return !pzi_more->IsError();
  510.        }
  511.     return FALSE;
  512. }
  513.  
  514. //----------------------------------------------------------------------------
  515. //   Description:    
  516. //    Parameters:
  517. //       Returns:    TRUE if successful.
  518. //----------------------------------------------------------------------------
  519. BOOL FN_M ZI_WINDOW::Multiple()
  520. {
  521.     SetString(FID(STR_RESULT3), "Multiple responses.");
  522.     SetString(FID(STR_RESULT4), "See messages.");
  523.     switch (z4_inq.request)
  524.         {
  525.         case Z4_RQ_CS:
  526.             PZI_Z5_LIST pzi_z5_list = new ZI_Z5_LIST(z4_inq.cx.cZip5, &z4_inq.cx.abZip5[0][0]);
  527.             if (pzi_z5_list == NULL)
  528.                 {
  529.                 ErrorNoMem();
  530.                 return FALSE;
  531.                 }
  532.             else if (pzi_z5_list->IsValid())
  533.                 {
  534.                 CHAR szFormat[81];
  535.  
  536.                 sprintf(szFormat, "%s, %s",
  537.                     z4_inq.cx.szCity, Z4_ST_FILE::Abbreviation(z4_inq.cx.state));
  538.                 pzi_z5_list->SetTitle(szFormat);
  539.                 pzi_z5_list->Show();
  540.                 }
  541.             break;
  542.  
  543.         case Z4_RQ_Z5:
  544.             PZI_CX_LIST pzi_cx_list = new ZI_CX_LIST(z4_inq.match.cRecords, z4_inq.match.arecid);
  545.             if (pzi_cx_list == NULL)
  546.                 {
  547.                 ErrorNoMem();
  548.                 return FALSE;
  549.                 }
  550.             else if (pzi_cx_list->IsValid())
  551.                 pzi_cx_list->Show();
  552.             break;
  553.  
  554.         case Z4_RQ_ZX:
  555.         case Z4_RQ_Z4:
  556.             PZI_Z4_LIST pzi_z4_list = new ZI_Z4_LIST(z4_inq.match.cRecords, z4_inq.match.arecid);
  557.           if (pzi_z4_list == NULL)
  558.                 {
  559.              ErrorNoMem();
  560.                 return FALSE;
  561.              }
  562.           else if (pzi_z4_list->IsValid())
  563.              pzi_z4_list->Show();
  564.             break;
  565.         }
  566.     return TRUE;
  567. }
  568.  
  569.  
  570. //----------------------------------------------------------------------------
  571. //   Description:    
  572. //    Parameters:
  573. //       Returns:    TRUE if successful.
  574. //----------------------------------------------------------------------------
  575. BOOL FN_M ZI_WINDOW::Parse()
  576. {
  577.     PZI_PARSE pzi_parse = new ZI_PARSE(&z4_inq.parse);
  578.     if (pzi_parse == NULL)
  579.         return ErrorNoMem();
  580.     else if (pzi_parse->IsValid())
  581.         pzi_parse->Show();
  582.     return TRUE;
  583. }
  584.  
  585.  
  586. //----------------------------------------------------------------------------
  587. //   Description:    
  588. //    Parameters:    
  589. //       Returns:    TRUE if successful.
  590. //----------------------------------------------------------------------------
  591. BOOL FN_M ZI_WINDOW::RecordCount(BOOL fRead)
  592. {
  593. static PCSZ pcszName = "RECORD_COUNT";
  594.  
  595.     CL_PARM cl_parm;
  596.     cl_parm.SetName(pcszName);
  597.     if (fRead)
  598.         {
  599.         if (!cl_parm.Get(NULL, pcszName))
  600.             return FALSE;
  601.         lRecordCount = MAX(0, (LONG)cl_parm);
  602.         }
  603.     CHAR szFormat[40];
  604.     sprintf(szFormat, "%ld INQUIRIES", lRecordCount);
  605.     SetPrompt(FID(PROMPT_INQURIES), szFormat);
  606.     if (!fRead)
  607.         {
  608.         cl_parm = lRecordCount;
  609.         if (!cl_parm.Set(pcszName))
  610.             return FALSE;
  611.         }
  612.     return TRUE;
  613. }
  614.  
  615.  
  616. //----------------------------------------------------------------------------
  617. //   Description:
  618. //    Parameters:
  619. //       Returns:    TRUE if successful.
  620. //----------------------------------------------------------------------------
  621. BOOL FN_M ZI_WINDOW::Results()
  622. {
  623.     PZI_RESULT pzi_result = new ZI_RESULT(szResults);
  624.     if (pzi_result == NULL)
  625.         return ErrorNoMem();
  626.     else if (pzi_result->IsValid())
  627.     pzi_result->Show();
  628.     return TRUE;
  629. }
  630.  
  631.  
  632. //----------------------------------------------------------------------------
  633. //   Description:
  634. //    Parameters:
  635. //       Returns:    
  636. //----------------------------------------------------------------------------
  637. VOID FN_M ZI_WINDOW::SetResults()
  638. {
  639.     szResults[0] = '\0';
  640.     if (z4_inq.result == Z4_RESULT_FAILURE)
  641.         {
  642.         SetString(FID(STR_RESULT3), "Inquiry not possible.");
  643.         SetString(FID(STR_RESULT4), "See messages.");
  644.         strcat(szResults,
  645.             "An internal application error has occurred.\r\n"
  646.             "Please verify that this product is installed correctly.\r\n");
  647.         }
  648.     else if (z4_inq.result == Z4_RESULT_ABORT)
  649.         {
  650.         SetString(FID(STR_RESULT3), "Inquiry cancelled by user.");
  651.         SetString(FID(STR_RESULT4));
  652.         strcat(szResults, "The inquiry was cancelled by the user.");
  653.         }
  654.     else if (z4_inq.result == Z4_RESULT_NOT_FOUND)
  655.         {
  656.         SetString(FID(STR_RESULT3), "Not found.");
  657.         SetString(FID(STR_RESULT4), "See messages.");
  658.         strcat(szResults,
  659.             "The inquiry could not be found.\r\n"
  660.             "Enter a more complete address and search again.\r\n");
  661.         }
  662.     else if (z4_inq.result == Z4_RESULT_INV_ST)
  663.         {
  664.         SetString(FID(STR_RESULT3), "Invalid state.");
  665.         SetString(FID(STR_RESULT4), "See messages.");
  666.         strcat(szResults,
  667.             "An invalid state was specified or no state was specified.\r\n"
  668.             "Enter a valid state and search again.\r\n");
  669.  
  670.         SetCurrent(FID(STR_INPUT_ST));
  671.         }
  672.     else if (z4_inq.result == Z4_RESULT_INV_CITY)
  673.         {
  674.         SetString(FID(STR_RESULT3), "Invalid city.");
  675.         SetString(FID(STR_RESULT4), "See messages.");
  676.         strcat(szResults,
  677.             "No matching city names were found.\r\n"
  678.             "Enter a valid city name and search again.\r\n");
  679.  
  680.         SetCurrent(FID(STR_INPUT_CITY));
  681.         }
  682.     else if (z4_inq.result == Z4_RESULT_INV_CSZ)
  683.         {
  684.         SetString(FID(STR_RESULT3), "Invalid City/State or ZIP.");
  685.         SetString(FID(STR_RESULT4), "See messages.");
  686.         strcat(szResults,
  687.             "Enter a valid city/state or ZIP code and search again.\r\n");
  688.  
  689.         SetCurrent(FID(STR_INPUT_CITY));
  690.         }
  691.     else
  692.         {
  693.         strcpy(szResults, "Inquiry successful.");
  694.         SetString(FID(STR_RESULT3), "Inquiry successful.");
  695.         SetString(FID(STR_RESULT4));
  696.         SetString(FID(STR_OUTPUT_ADDR2), z4_inq.std.szAddr2);
  697.        SetString(FID(STR_OUTPUT_LL), z4_inq.std.szLastLine);
  698.        switch (z4_inq.request)
  699.            {
  700.            case Z4_RQ_CS:
  701.                SetResultsCS();
  702.                break;
  703.    
  704.            case Z4_RQ_Z4:
  705.                SetResultsZ4();
  706.                break;
  707.    
  708.            case Z4_RQ_Z5:
  709.                SetResultsZ5();
  710.                break;
  711.    
  712.            case Z4_RQ_ZX:
  713.                SetResultsZX();
  714.                break;
  715.            }
  716.         }
  717.     Flags();
  718.     return ;
  719. }
  720.  
  721.  
  722. //----------------------------------------------------------------------------
  723. //   Description:
  724. //    Parameters:
  725. //       Returns:    
  726. //----------------------------------------------------------------------------
  727. VOID FN_M ZI_WINDOW::SetResultsCS()
  728. {
  729.         PCSZ pcszCity  = z4_inq.cx.szCity;
  730.         PCSZ pcszState = Z4_ST_FILE::Abbreviation(z4_inq.cx.state);
  731.         PCSZ pcszZip5  = z4_inq.std.szZip5;
  732.         CHAR szFormat[81];
  733.  
  734.         sprintf(szFormat, "%s, %s is in ZIP:", pcszCity, pcszState);
  735.         SetString(FID(STR_RESULT1), szFormat);
  736.         SetString(FID(STR_RESULT2), pcszZip5);
  737.  
  738.         if (z4_inq.result == Z4_RESULT_EXACT)
  739.                 {
  740.                 sprintf(szResults,
  741.                         "An exact match was made to %s, %s in ZIP code %s.\r\n",
  742.                         pcszCity, pcszState, pcszZip5);
  743.                 SetString(FID(STR_RESULT3), "Exact match.");
  744.                 SetString(FID(STR_RESULT4));
  745.                 }
  746.         else                                                                    
  747.                 {
  748.                 sprintf(szResults,
  749.                         "%u ZIP codes were found in %s, %s.\r\n"
  750.                         "ZIP code %s was selected.\r\n",
  751.                         z4_inq.match.cRecords, pcszCity, pcszState, pcszZip5);
  752.                         
  753.                 SetString(FID(STR_RESULT3), "Multiple response.");
  754.                 SetString(FID(STR_RESULT4), "See messages.");
  755.                 }
  756.         return ;
  757. }
  758.  
  759.  
  760. //----------------------------------------------------------------------------
  761. //   Description:
  762. //    Parameters:
  763. //       Returns:       
  764. //----------------------------------------------------------------------------
  765. VOID FN_M ZI_WINDOW::SetResultsZ4()
  766. {
  767.         if (z4_inq.result == Z4_RESULT_EXACT)
  768.                 {
  769.                 sprintf(szResults, "An exact match was made.\r\n");
  770.                 SetString(FID(STR_RESULT3), "Exact match.");
  771.                 SetString(FID(STR_RESULT4));
  772.                 }
  773.         else
  774.                 {
  775.                 sprintf(szResults,
  776.                         "%u records were found which matched your input. "
  777.                         "A single record was selected.\r\n",
  778.                         z4_inq.match.cRecords);
  779.                 SetString(FID(STR_RESULT3), "Multiple response.");
  780.                 SetString(FID(STR_RESULT4), "See messages.");
  781.                 }
  782. #if 0
  783.         if (z4_inq.match.rec[Z4_REC_BEST].z4.szCris[0] && !z4_inq.fNonDeliverable)
  784.                 {
  785.                 sprintf(strchr(szResults, '\0'),
  786.                         "The carrier route for this address is %s.\r\n",
  787.                         z4_inq.match.rec[Z4_REC_BEST].z4.szCris);
  788.                 }
  789. #endif
  790.         if (!z4_inq.std.szZip4[0])
  791.                 {
  792.                 CHAR szFormat[81];
  793.                 sprintf(szFormat, "The correct ZIP code is:");
  794.                 SetString(FID(STR_RESULT1), szFormat);
  795.                 SetString(FID(STR_RESULT2), z4_inq.std.szZip5);
  796.                 }
  797.         else
  798.                 {
  799.                 CHAR szFormat[81];
  800.                 sprintf(szFormat, "The correct ZIP+4 is:");
  801.                 SetString(FID(STR_RESULT1), szFormat);
  802.                 SetString(FID(STR_RESULT2), z4_inq.std.szZip4);
  803.                 }
  804.         return ;
  805. }
  806.  
  807.  
  808. //----------------------------------------------------------------------------
  809. //   Description:
  810. //    Parameters:
  811. //       Returns:       
  812. //----------------------------------------------------------------------------
  813. VOID FN_M ZI_WINDOW::SetResultsZ5()
  814. {
  815.         PCSZ pcszCity  = z4_inq.cs.szCity;
  816.         PCSZ pcszState = Z4_ST_FILE::Abbreviation(z4_inq.cs.state);
  817.         PCSZ pcszZip5  = z4_inq.std.szZip5;
  818.         CHAR szFormat[81];
  819.  
  820.         sprintf(szFormat, "%s, %s is in ZIP:", pcszCity, pcszState);
  821.         SetString(FID(STR_RESULT1), szFormat);
  822.         SetString(FID(STR_RESULT2), pcszZip5);
  823.         if (z4_inq.result == Z4_RESULT_EXACT)
  824.                 {
  825.                 sprintf(szResults,
  826.                         "An exact match to %s, %s in ZIP code %s was made.\r\n",
  827.                         pcszCity, pcszState, pcszZip5);
  828.                 SetString(FID(STR_RESULT3), "Exact match.");
  829.                 SetString(FID(STR_RESULT4));
  830.                 }
  831.         else                                                                    
  832.                 {
  833.                 sprintf(szResults,
  834.                         "%u city names were found in ZIP code %s.\r\n"
  835.                         "%s, %s was selected.\r\n",
  836.                         z4_inq.match.cRecords, pcszZip5, pcszCity, pcszState);
  837.                 SetString(FID(STR_RESULT3), "Multiple response.");
  838.                 SetString(FID(STR_RESULT4), "See messages.");
  839.                 }
  840.         return ;
  841. }
  842.  
  843.  
  844. //----------------------------------------------------------------------------
  845. //   Description:
  846. //    Parameters:
  847. //       Returns:       
  848. //----------------------------------------------------------------------------
  849. VOID FN_M ZI_WINDOW::SetResultsZX()
  850. {
  851.         if (z4_inq.result == Z4_RESULT_EXACT)
  852.                 {
  853.                 sprintf(szResults,
  854.                         "An exact match was made to ZIP+4 code %s.\r\n", z4_inq.std.szZip4);
  855.                 SetString(FID(STR_RESULT3), "Exact match.");
  856.                 SetString(FID(STR_RESULT4));
  857.                 }
  858.         else                                                                    
  859.                 {
  860.                 sprintf(szResults,
  861.                         "%u records were found with ZIP+4 code %s.\r\n"
  862.                         "A single record was selected.\r\n",
  863.                         z4_inq.match.cRecords, z4_inq.std.szZip4);
  864.                 SetString(FID(STR_RESULT3), "Multiple response.");
  865.                 SetString(FID(STR_RESULT4), "See messages.");
  866.                 }
  867.         return ;
  868. }
  869.  
  870.  
  871. //----------------------------------------------------------------------------
  872. //   Description:    Display city/state list
  873. //    Parameters:
  874. //       Returns:    TRUE if successful.
  875. //----------------------------------------------------------------------------
  876. BOOL FN_M ZI_WINDOW::State()
  877. {
  878.     if (!CheckCounter())
  879.         return FALSE;
  880.  
  881.     Get();
  882.     z4_inq.parse.LastLine(z4_inq.szZip, z4_inq.szCity, z4_inq.szState);
  883.  
  884.     PZI_ST pzi_st = new ZI_ST(z4_inq.parse.state);
  885.     if (pzi_st == NULL)
  886.         return ErrorNoMem();
  887.     else if (pzi_st->IsValid())
  888.         pzi_st->Show();
  889.     return TRUE;
  890. }
  891.  
  892. //----------------------------------------------------------------------------
  893. //   Description:    
  894. //    Parameters:
  895. //       Returns:    TRUE if successful.
  896. //----------------------------------------------------------------------------
  897. BOOL FN_M ZI_WINDOW::Subscribe()
  898. {
  899.     PZI_SUBSCRIBE pzi_subscribe = new ZI_SUBSCRIBE;
  900.     if (pzi_subscribe == NULL)
  901.         return ErrorNoMem();
  902.     else if (pzi_subscribe->IsValid())
  903.         pzi_subscribe->Show();
  904.     return TRUE;
  905. }
  906.  
  907.  
  908. //----------------------------------------------------------------------------
  909. //   Description:    Event monitor function.
  910. //    Parameters:    msg        Event code
  911. //                        pv1            Data pointer 1
  912. //                        pv2            Data pointer 2
  913. //       Returns:    Event code
  914. //----------------------------------------------------------------------------
  915. ZN_MSG FN_M ZI_WINDOW::User(ZN_MSG msg, PVOID pv1, PVOID pv2)
  916. {
  917.     switch (msg)
  918.         {
  919.         case ZN_MSG_INIT:
  920.             RecordCount(TRUE);
  921.                                                     // Also sets OWNERDRAW for right justify under windows
  922.             SetStringColor(FID(STR_RESULT1), ZN_CLR_BLACK);
  923.             SetStringColor(FID(STR_RESULT2), ZN_CLR_RED);
  924.             SetStringColor(FID(STR_RESULT4), ZN_CLR_LIGHTBLUE);
  925.             Clear();
  926.             return msg;
  927.  
  928.         case ZN_MSG_TERMINATE:
  929.             return msg;
  930.         }
  931.     if (IsError())                                // Error condition
  932.         return msg;
  933.     switch (msg)
  934.         {
  935.         case ZN_MSG_HELP:
  936.             Help((ZN_HELP)(LONG)pv1, (PSZ)pv2);
  937.             break;
  938.  
  939.         case BUTTON_CLEAR:
  940.         case MENU_EDIT_CLEAR:
  941.             Clear();
  942.             break;
  943.  
  944.         case BUTTON_SEARCH:
  945.             Inquiry();
  946.             break;
  947.  
  948.         case BUTTON_COPY:
  949.             Paste(z4_inq.std.szAddress);
  950.             break;
  951.  
  952.         case BUTTON_RESULTS:
  953.             Results();
  954.             break;
  955.  
  956.         case ZI_MSG_ADDR:
  957. //            SetString(FID(STR_INPUT_ADDR1), (PSZ)pv1);
  958.             SetString(FID(STR_INPUT_ADDR2), (PSZ)pv2);
  959.             break;
  960.  
  961.         case ZI_MSG_STATE:
  962.             SetString(FID(STR_INPUT_ST), (PSZ)pv2);
  963.             break;
  964.  
  965.         case ZI_MSG_CITY:                        
  966.             SetString(FID(STR_INPUT_CITY), (PSZ)pv2);
  967.             break;
  968.  
  969.         case ZI_MSG_ZIP5:
  970.             SetString(FID(STR_INPUT_ZIP), (PSZ)pv2);
  971.             break;
  972.     
  973.         case MENU_EDIT:
  974.             ExitRequest();
  975.             break;
  976.  
  977.         case MENU_FILE_CONFIGURE:
  978.             Configure();
  979.             break;
  980.  
  981.         case MENU_SUBSCRIBE:
  982.             Subscribe();
  983.             break;
  984.  
  985.         case MENU_FILE_EXIT:
  986.             ExitRequest();
  987.             break;
  988.  
  989.         case ZI_MSG_CLICK:
  990.             lRecordCount = MAX(0, lRecordCount - 1);
  991.             RecordCount();
  992.             break;
  993.  
  994.         case ZI_MSG_RECORD:
  995.             RecordCount(TRUE);
  996.             break;
  997.  
  998.         case ZI_MSG_SELECT:
  999.             z4_inq.Select((SIZET)pv1);
  1000.             SetResults();
  1001.             break;
  1002.  
  1003.         case TB_HELP:
  1004.             if (DebugMode())
  1005.                 {
  1006.                 Expert();                        // Display expert (debugging) menu window
  1007.                 break;
  1008.                 }
  1009.             // Else fall through
  1010.         case MENU_HELP_INDEX:
  1011.             HelpIndex();
  1012.             break;
  1013.  
  1014.         case ZI_MSG_ABORT:
  1015.             fAbort = TRUE;
  1016.             break;
  1017.  
  1018.         case TB_PRODUCTS:
  1019.         case MENU_OTHER:
  1020.             More();
  1021.             break;
  1022.  
  1023.         case ZI_MSG_ST:
  1024.         case MENU_VIEW_STATES:
  1025.         case TB_STATES:
  1026.             State();
  1027.             break;
  1028.  
  1029.         case ZI_MSG_AB:
  1030.         case MENU_VIEW_ABBR:
  1031.             Abbrev();
  1032.             break;
  1033.  
  1034.         case ZI_MSG_Z5:
  1035.             Z5();
  1036.             break;
  1037.  
  1038.         case ZI_MSG_Z4:
  1039.             Z4();
  1040.             break;
  1041.  
  1042.         case ZI_MSG_ZX:
  1043.             ZX();
  1044.             break;
  1045.  
  1046.         case ZI_MSG_PARSE:
  1047.             Parse();
  1048.             break;
  1049.  
  1050.         case ZI_MSG_INIT:
  1051.             z4_inq.Destroy();                            // Close data files
  1052.                                                             // Re-initialize and open data files
  1053.             if (!Z4_INQ::Start(Z4_INQ_REINIT|Z4_INQ_ALL))    
  1054.                 {
  1055.                 Error("There is a problem accessing the data files.\n"
  1056.                         "Verify that the program is configured correctly.");
  1057.                 }
  1058.             break;
  1059.  
  1060.         case MENU_VIEW_CITIES:
  1061.         case TB_CITIES:
  1062.         case ZI_MSG_CX:
  1063.             CX();
  1064.             break;
  1065.  
  1066.         case ZI_MSG_CS:
  1067.             CS();
  1068.             break;
  1069.  
  1070.         case ZI_MSG_PF:
  1071.             NotDone();
  1072.             break;
  1073.         }
  1074.     return msg;
  1075. }
  1076.  
  1077.  
  1078. //----------------------------------------------------------------------------
  1079. //   Description:    Display city/state list
  1080. //    Parameters:
  1081. //       Returns:    TRUE if successful.
  1082. //----------------------------------------------------------------------------
  1083. BOOL FN_M ZI_WINDOW::Z4()
  1084. {
  1085.     if (!CheckCounter())
  1086.         return FALSE;
  1087.  
  1088.     PZI_Z4 pzi_z4 = new ZI_Z4();
  1089.     if (pzi_z4 == NULL)
  1090.        return ErrorNoMem();
  1091.     else if (pzi_z4->IsValid())
  1092.        pzi_z4->Show();
  1093.     return TRUE;
  1094. }
  1095.  
  1096.  
  1097. //----------------------------------------------------------------------------
  1098. //   Description:    
  1099. //    Parameters:
  1100. //       Returns:    TRUE if successful.
  1101. //----------------------------------------------------------------------------
  1102. BOOL _LOADDS_ FN_M ZI_WINDOW::Z4Callback(SHORT sDone)
  1103. {
  1104.     if (pzi_cancel)
  1105.         pzi_cancel->NextBitmap(sDone ? 99: -1);
  1106.  
  1107.     ZI_WINDOW::Process();
  1108.     return !fAbort;
  1109. }
  1110.  
  1111.  
  1112.  
  1113. //----------------------------------------------------------------------------
  1114. //   Description:    Display city/state list
  1115. //    Parameters:
  1116. //       Returns:    TRUE if successful.
  1117. //----------------------------------------------------------------------------
  1118. BOOL FN_M ZI_WINDOW::Z5()
  1119. {
  1120.     if (!CheckCounter())
  1121.         return FALSE;
  1122.  
  1123.     Get();
  1124.     z4_inq.parse.LastLine(z4_inq.szZip, z4_inq.szCity, z4_inq.szState);
  1125.  
  1126.     PZI_Z5 pzi_z5 = new ZI_Z5(z4_inq.parse.szZip5);
  1127.     if (pzi_z5 == NULL)
  1128.         return ErrorNoMem();
  1129.     else if (pzi_z5->IsValid())
  1130.         pzi_z5->Show();
  1131.     return TRUE;
  1132. }
  1133.  
  1134.  
  1135. //----------------------------------------------------------------------------
  1136. //   Description:    Display city/state list
  1137. //    Parameters:
  1138. //       Returns:    TRUE if successful.
  1139. //----------------------------------------------------------------------------
  1140. BOOL FN_M ZI_WINDOW::ZX()
  1141. {
  1142.     if (!CheckCounter())
  1143.         return FALSE;
  1144.  
  1145.     Get();
  1146.     z4_inq.parse.LastLine(z4_inq.szZip, z4_inq.szCity, z4_inq.szState);
  1147.  
  1148.     CHAR szZip4[MAX_ZIP4+1];
  1149.     if (z4_inq.parse.szZip5[0])
  1150.         {
  1151.         strcpy(szZip4, z4_inq.parse.szZip5);
  1152.         if (z4_inq.parse.szAddon[0])
  1153.             strcat(szZip4, z4_inq.parse.szAddon);
  1154.         else
  1155.             strcat(szZip4, "0000");
  1156.         }
  1157.     else
  1158.         szZip4[0] = '\0';
  1159.  
  1160.     PZI_ZX pzi_zx = new ZI_ZX(szZip4);;
  1161.     if (pzi_zx == NULL)
  1162.         return ErrorNoMem();
  1163.     else if (pzi_zx->IsValid())
  1164.         pzi_zx->Show();
  1165.     return TRUE;
  1166. }
  1167. //----------------------------------------------------------------------------
  1168. //------------------------------- End of File --------------------------------
  1169. //----------------------------------------------------------------------------
  1170.